<template>
  <div class="menu">
    <div class="list">
      <div
        class="item"
        v-for="(item, index) in list"
        :key = "index"
        @click="toPage(item.name)"
        :class="{ active: routeName === item.name }"
      >
        <span><i :class="item.icon"></i>{{ item.title }}</span>
      </div>
    </div>
  </div>
</template>

<script>

export default {
  name: "Menu",
  props: {
    routeName: String,
  },
  data() {
    return {
      list: [
        {
          name: "partManagement",
          icon: "dashboard",
          title: "零件维护",
        },
        {
          name: "productManagement",
          icon: "table",
          title: "产品维护",
        },
        {
          name: "productBOM",
          icon: "profile",
          title: "产品BOM表",
        },
        {
          name: "partInput",
          icon: "form",
          title: "零件入库记录",
        },
        {
          name: "productOutput",
          icon: "profile",
          title: "产品出库记录",
        },
      ],
    };
  },
  methods: {
    toPage(name) {
      if (this.$route.name === name) {
        return;
      }
      this.$router
        .push({
          name,
        })
        .catch((res) => {});
    },
  },
};
</script>

<style scoped lang="scss">
.menu {
  height: 100%;
  padding: 30px 10px 10px 10px;
  background: #f0f5f6;
  color: #76808c;

  .list {
    height: 100vh;
    overflow-y: auto;
    overflow-x: hidden;
    display: flex;
    flex-direction: column;
    align-items: center;
  }

  .item {
    margin-top: 20px;
    cursor: pointer;
    width: 100%;
    height: 60px;
    line-height: 40px;
    text-indent: 10px;
    text-align: center;
    font-size: 30px;
    border-radius: 5px;
    display: flex;
    align-items: center;

    &:hover {
      background: #e4e8ec;
      color: #333333;
    }

    &.active {
      background: #1890ff;
      color: #ffffff;
    }
  }
}
</style>
